package com.lfg.leetcode.leetcode0;

public class No81search {

    public static void main(String[] args) {
        boolean ret = search(new int[]{2,5,6,0,0,2}, 0);
        System.out.println("[" + ret + "]");
    }


    public static boolean search(int[] nums, int target) {

        int low = 0;
        int high = nums.length - 1;

        while (low <= high) {
            int mid = (low + high) / 2;
            if (nums[mid] == target) {
                return true;
            }
            if (nums[low] == nums[mid] && nums[mid] == nums[high]) {
                low++;
                high--;
            } else if (nums[mid] <= nums[high]) { //右边顺序
                if (nums[mid] <= target && target <= nums[high]) {
                    low = mid + 1;
                } else {
                    high = mid - 1;
                }
            } else { //左边顺序
                if (nums[mid] >= target && target >= nums[low]) {
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
        }
        return false;
    }

}

